home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Wipes ƒ / Four-corner scroll.c < prev    next >
Text File  |  1994-04-15  |  6KB  |  163 lines

  1. /**********************************************************************\
  2.  
  3. File:        Four-corner scroll.c
  4.  
  5. Purpose:    Graphic effect from offscreen bitmap to main window (on
  6.             screen).  See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. #define CorrectTime 4
  28. #define theWindowWidth (boundsRect.right-boundsRect.left)
  29. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  30.  
  31. pascal short FourCornerScroll(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  32.  
  33. /* Four scrolls in one, each confined to a section of the screen which includes
  34.    the center and one side, and all four scrolls moving towards the center.
  35.    Kinda slow on my Mac IIci in 8-bit; fine in 4-bit or fewer. */
  36.    
  37. pascal short FourCornerScroll(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  38. {
  39.     int            x;
  40.     Rect        theTopRect, topdest, theBottomRect, bottomdest;
  41.     Rect        theLeftRect, leftdest, theRightRect, rightdest;
  42.     Rect        topscrollsource, topscrolldest, bottomscrollsource, bottomscrolldest;
  43.     Rect        leftscrollsource, leftscrolldest, rightscrollsource, rightscrolldest;
  44.     RgnHandle    toprgn,bottomrgn,leftrgn,rightrgn;
  45.     int            cx,cy;
  46.     int            HBoxSize,BoxSize;
  47.     
  48.     BoxSize=theWindowHeight/50;
  49.     HBoxSize=theWindowWidth/50;
  50.     
  51.     cx = boundsRect.left + theWindowWidth / 2;
  52.     cy = boundsRect.top + theWindowHeight / 2;
  53.  
  54.     toprgn=NewRgn();
  55.     SetEmptyRgn(toprgn);
  56.     MoveTo(boundsRect.left, boundsRect.top);
  57.     OpenRgn();                               /* top region */
  58.         Line(theWindowWidth,0);
  59.         LineTo(cx,cy);
  60.         LineTo(boundsRect.left, boundsRect.top);
  61.     CloseRgn(toprgn);
  62.     
  63.     bottomrgn=NewRgn();
  64.     SetEmptyRgn(bottomrgn);
  65.     MoveTo(boundsRect.left, boundsRect.bottom);
  66.     OpenRgn();                               /* bottom region */
  67.         Line(theWindowWidth, 0);
  68.         LineTo(cx,cy);
  69.         LineTo(boundsRect.left, boundsRect.bottom);
  70.     CloseRgn(bottomrgn);
  71.     
  72.     leftrgn=NewRgn();
  73.     SetEmptyRgn(leftrgn);
  74.     MoveTo(boundsRect.left, boundsRect.top);
  75.     OpenRgn();                               /* left region */
  76.         Line(0,theWindowHeight);
  77.         LineTo(cx,cy);
  78.         LineTo(boundsRect.left, boundsRect.top);
  79.     CloseRgn(leftrgn);
  80.     
  81.     rightrgn=NewRgn();
  82.     SetEmptyRgn(rightrgn);
  83.     MoveTo(boundsRect.right, boundsRect.top);
  84.     OpenRgn();                               /* right region */
  85.         Line(0, theWindowHeight);
  86.         LineTo(cx,cy);
  87.         LineTo(boundsRect.right, boundsRect.top);
  88.     CloseRgn(rightrgn);
  89.     
  90.     topscrollsource=bottomscrollsource=leftscrollsource=rightscrollsource=
  91.         topdest=bottomdest=leftdest=rightdest=boundsRect;
  92.     
  93.     topscrollsource.bottom-=cy-boundsRect.top+BoxSize;
  94.     topscrolldest = topscrollsource;
  95.     OffsetRect(&topscrolldest, 0, BoxSize);        /* dest. strip for top scroll */
  96.     topdest.bottom=topdest.top+BoxSize;            /* dest. strip for new data on top */
  97.     SetRect(&theTopRect, boundsRect.left, cy-BoxSize, boundsRect.right, cy);
  98.     
  99.     bottomscrollsource.top+=cy-boundsRect.top+BoxSize;
  100.     bottomscrolldest=bottomscrollsource;
  101.     OffsetRect(&bottomscrolldest, 0, -BoxSize);
  102.     bottomdest.top=bottomdest.bottom-BoxSize;
  103.     SetRect(&theBottomRect, boundsRect.left, cy, boundsRect.right, cy+BoxSize);
  104.     
  105.     leftscrollsource.right-=cx-boundsRect.left+HBoxSize;
  106.     leftscrolldest=leftscrollsource;
  107.     OffsetRect(&leftscrolldest,HBoxSize,0);
  108.     leftdest.right=leftdest.left+HBoxSize;
  109.     SetRect(&theLeftRect, cx-HBoxSize, boundsRect.top, cx, boundsRect.bottom);
  110.     
  111.     rightscrollsource.left+=cx-boundsRect.left+HBoxSize;
  112.     rightscrolldest=rightscrollsource;
  113.     OffsetRect(&rightscrolldest,-HBoxSize,0);
  114.     rightdest.left=rightdest.right-HBoxSize;
  115.     SetRect(&theRightRect, cx, boundsRect.top, cx+HBoxSize, boundsRect.bottom);
  116.     
  117.     /* for each section (top, bottom, left, right) we need to do the scroll part,
  118.     which takes a section of the dest. window and moves it, then we need to copy
  119.     in the new data from the source window */
  120.     for(x = cy - BoxSize; x >= boundsRect.top; x -= BoxSize)
  121.     {
  122.         StartTiming();
  123.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  124.                 &topscrollsource, &topscrolldest, 0, toprgn);
  125.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  126.                 &theTopRect, &topdest, 0, toprgn);
  127.         theTopRect.bottom-=BoxSize;
  128.         theTopRect.top-=BoxSize;
  129.         
  130.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  131.                 &bottomscrollsource, &bottomscrolldest, 0, bottomrgn);
  132.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  133.                 &theBottomRect, &bottomdest, 0, bottomrgn);
  134.         theBottomRect.top+=BoxSize;
  135.         theBottomRect.bottom+=BoxSize;
  136.         
  137.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  138.                 &leftscrollsource, &leftscrolldest, 0, leftrgn);
  139.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  140.                 &theLeftRect, &leftdest, 0, leftrgn);
  141.         theLeftRect.left-=HBoxSize;
  142.         theLeftRect.right-=HBoxSize;
  143.         
  144.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  145.                 &rightscrollsource, &rightscrolldest, 0, rightrgn);
  146.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  147.                 &theRightRect, &rightdest, 0, rightrgn);
  148.         theRightRect.left+=HBoxSize;
  149.         theRightRect.right+=HBoxSize;
  150.         TimeCorrection(CorrectTime);
  151.     }
  152.     
  153.     CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  154.         &boundsRect, &boundsRect, 0, 0L);    /* in case we missed any bits */
  155.  
  156.     DisposeRgn(toprgn);
  157.     DisposeRgn(bottomrgn);
  158.     DisposeRgn(leftrgn);
  159.     DisposeRgn(rightrgn);
  160.     
  161.     return 0;
  162. }
  163.